/* 
 * File:   vbop.hpp
 * Author: gustavo
 *
 * Created on August 10, 2012, 1:57 AM
 */

#ifndef VBOP_HPP
#define	VBOP_HPP

#include <stdio.h>
#include <math.h>

#define N 4

/* = Data visualization ================================================= */

/**
 * 
 * @param m
 * @param u
 * @param incu
 * @param val
 */
template <typename T> inline void v_print(int m, const T * u, int incu) {

	for (; m > 0; --m, u += incu) {
		printf("%.3f\n", *u);
	}

	printf("\n\n");

}

/* = Data manipulation ================================================== */

/**
 * u[0...m-1] = val
 * @param m
 * @param u
 * @param incu
 * @param val
 */
template <typename T> inline void v_set(int m, T * u, int incu, T val) {

	if (incu != 1) {

		for (; m > 0; --m, u += incu) {
			*u = val;
		}

	} else {

		int n4 = m / N;
		int left = m % N;
		int iu = incu * N;

		for (; n4 > 0; --n4, u += iu) {
			u[0] = u[1] = u[2] = u[3] = val;
		}
		for (; left > 0; --left, u += incu) {
			u[0] = val;
		}

	}

}

/**
 * u[0...m-1] = v[0...m-1]
 * @param m
 * @param u
 * @param incu
 * @param v
 * @param incv
 */
template <typename T> inline void v_copy(int m, T * u, int incu, const T * v, int incv) {


	if (incu != 1 || incv != 1) {

		for (; m > 0; --m, u += incu, v += incv) {
			*u = *v;
		}

	} else {

		int n4 = m / N;
		int left = m % N;
		int iu = incu * N;
		int iv = incv * N;

		for (; n4 > 0; --n4, u += iu, v += iv) {
			u[0] = v[0];
			u[1] = v[1];
			u[2] = v[2];
			u[3] = v[3];
		}
		for (; left > 0; --left, u += incu, v += incv) {
			u[0] = v[0];
		}

	}

}

/**
 * u[0...m-1] = v[0...m-1]
 * @param m
 * @param u
 * @param incu
 * @param v
 * @param incv
 */
template <typename T> inline void v_move(int m, T * u, int incu, const T * v, int incv) {

	if (incu != 1 || incv != 1) {

		for (; m > 0; --m, u += incu, v += incv) {
			*u = *v;
		}

	} else {

		int n4 = m / N;
		int left = m % N;
		int iu = incu * N;
		int iv = incv * N;

		for (; n4 > 0; --n4, u += iu, v += iv) {
			u[0] = v[0];
			u[1] = v[1];
			u[2] = v[2];
			u[3] = v[3];
		}
		for (; left > 0; --left, u += incu, v += incv) {
			u[0] = v[0];
		}

	}

}




#endif	/* VBOP_HPP */

